@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  * {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
  }

  html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: #f5f5f5;
    /* 移动端触摸优化 */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* 防止页面缩放 */
    touch-action: manipulation;
  }

  #root {
    height: 100%;
  }

  /* 移动端输入框优化 */
  input, textarea, select {
    -webkit-appearance: none;
    border-radius: 0;
    font-size: 16px; /* 防止iOS缩放 */
  }

  /* 移动端按钮优化 */
  button {
    -webkit-appearance: none;
    border: none;
    outline: none;
    background: none;
    font-size: 16px;
  }

  /* 移动端链接优化 */
  a {
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
  }
}

@layer components {
  .mobile-container {
    max-width: 100%;
    margin: 0 auto;
    background: white;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
  }

  .safe-area-top {
    padding-top: env(safe-area-inset-top);
  }

  .safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .safe-area-left {
    padding-left: env(safe-area-inset-left);
  }

  .safe-area-right {
    padding-right: env(safe-area-inset-right);
  }

  /* 隐藏滚动条 */
  .scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }

  .scrollbar-hide::-webkit-scrollbar {
    display: none;
  }

  /* 文本截断 */
  .line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* 移动端滚动优化 */
  .mobile-scroll {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }

  /* 触摸反馈 */
  .touch-feedback {
    transition: all 0.15s ease;
  }

  .touch-feedback:active {
    transform: scale(0.98);
    opacity: 0.8;
  }

  /* 移动端卡片样式 */
  .mobile-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    overflow: hidden;
  }

  /* 移动端按钮样式 */
  .mobile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
    min-height: 44px; /* 移动端触摸目标最小尺寸 */
  }

  .mobile-btn-primary {
    background: linear-gradient(135deg, #3B82F6, #1D4ED8);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  }

  .mobile-btn-primary:active {
    transform: translateY(1px);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
  }

  /* 移动端输入框样式 */
  .mobile-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    font-size: 16px;
    background: white;
    transition: border-color 0.2s ease;
  }

  .mobile-input:focus {
    outline: none;
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  }

  /* 移动端间距系统 */
  .mobile-px {
    padding-left: 16px;
    padding-right: 16px;
  }

  .mobile-py {
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .mobile-mx {
    margin-left: 16px;
    margin-right: 16px;
  }

  .mobile-my {
    margin-top: 16px;
    margin-bottom: 16px;
  }

  /* 安全区域适配 */
  @supports (padding: max(0px)) {
    .safe-area-top {
      padding-top: max(env(safe-area-inset-top), 16px);
    }

    .safe-area-bottom {
      padding-bottom: max(env(safe-area-inset-bottom), 16px);
    }

    .safe-area-left {
      padding-left: max(env(safe-area-inset-left), 16px);
    }

    .safe-area-right {
      padding-right: max(env(safe-area-inset-right), 16px);
    }
  }

  /* 移动端响应式断点 */
  @media (max-width: 375px) {
    .mobile-px {
      padding-left: 12px;
      padding-right: 12px;
    }
    
    .mobile-mx {
      margin-left: 12px;
      margin-right: 12px;
    }
  }

  @media (min-width: 768px) {
    .mobile-container {
      max-width: 414px;
      border-left: 1px solid #E5E7EB;
      border-right: 1px solid #E5E7EB;
    }
  }
}
